package test.nettys.zerocopy;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @Author wangshaopeng
 * @Date 2021/8/25
 */
public class NewClient {


    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost", 8899));
        socketChannel.configureBlocking(true);

        String path = "/Users/shaopeng/Downloads/ideaIU-2020.2.4.dmg";

        FileChannel fileChannel = new FileInputStream(path).getChannel();

        long start = System.currentTimeMillis();

        fileChannel.transferTo(0, fileChannel.size(), socketChannel);

        System.out.println(System.currentTimeMillis()-start);
        fileChannel.close();
    }
}
